import BaseCharacterElement from "../BaseCharacterElement";

export default class BaseState {

    public characterEle: BaseCharacterElement;
    public animName: string;
    public animation: cc.Animation;
    public sketonAnim: sp.Skeleton;
    public animCompleate: Function;
    public animCaller: any;

    public constructor(ele: BaseCharacterElement, _animName: string) {
        this.characterEle = ele;
        this.animName = _animName;

        this.animation = this.characterEle.characterAnim;
        this.sketonAnim = this.characterEle.sketonAnim;
    }

    public EnterState(): void {
        this.sketonAnim.setAnimation(0, this.animName, true);
        this.sketonAnim.paused = false;
        var that = this;
        this.sketonAnim.setCompleteListener((e: sp.spine.TrackEntry) => {
            if (e.animation.name == "attack") {
                that.characterEle.changeState(that.characterEle.runState);
                that.animCompleate?.call(that.animCaller);
            }
        });
        // this.animation.play(this.animName);
    }

    public ExitState(): void {
        // this.animation.stop();
        this.sketonAnim.paused = true;

    }

    public UpdataState(dt: number): void {

    }


}
